package com.pactera.madp.cp.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.pactera.madp.cp.api.dto.track.BehaviorTrackDto;
import com.pactera.madp.cp.api.entity.BehaviorTrackEntity;
import com.pactera.madp.cp.common.constant.BehaviorTrackFormatConst;
import com.pactera.madp.cp.service.IWorkContactService;
import com.pactera.madp.cp.service.IWorkEmployeeService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class BehaviorTrackTaskServiceImpl extends BaseBehaviorTrackServer {

    @Override
    public void handleEvent(BehaviorTrackDto dto, IWorkEmployeeService workEmployeeService,
                            IWorkContactService workContactService, HttpServletResponse response) throws Exception{
        //事件处理
        BehaviorTrackEntity entity = new BehaviorTrackEntity();
        BeanUtil.copyProperties(dto, entity);
        baseHandleEvent(entity, workEmployeeService, workContactService, this, response);
    }

    @Override
    protected String buildData(BehaviorTrackEntity entity) {
        List<String> datas = new ArrayList<>();
        datas.add(entity.getUsername());
        datas.add(entity.getTitle());
        datas.add(entity.getUrl());
        /*datas.add(entity.getWxUserId());
        datas.add(entity.getWxExternalUserid());
        datas.add(String.valueOf(entity.getCorpId()));
        datas.add(String.valueOf(entity.getTenantId()));*/
        String content = String.format(BehaviorTrackFormatConst.TaskFormFormat, datas.toArray(new String[datas.size()]));
        return content;
    }

}